<?php 
class GoodsTypeController extends Controller{
	public $db;
	//构造函数，格式化表
	public function __init(){
		$this->db=K('Goods_Type');
	}
	//index方法显示商品类型列表
	public function index(){
		$date=$this->db->all();
		$this->assign('date',$date);
		$this->display();
	}
	//add方法添加商品类型
	public function add(){
		if (IS_POST) {
			//用model类中的方法添加数据
			if($this->db->addGoodsType()){
				$this->success('添加成功','GoodsType/index');
			}else{
				$this->error($this->db->error);
			}
		}else{
			$this->display();
		}
	}
	//编辑类型
	public function edit(){
		if (IS_POST){
			if ($this->db->editGoodsType()){
				$this->success('修改成功 ', 'index');
			}else{
				$this->error($this->db->error);
			}
		}else{
			$field=$this->db->find(Q('gtid'));
			$this->assign('field',$field);
			$this->display();
		}
	}

}


 ?>